package com.haiyou.common.spring.listener;

import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import com.google.common.eventbus.Subscribe;
import com.haiyou.common.event.asyc.AbstractAsyncEventObserver;
import com.haiyou.common.spring.util.SpringUtil;
import com.haiyou.common.system.Properties;
import com.haiyou.common.system.SpringEnvironmentProperties;
import com.haiyou.common.system.SystemConfigModifiedEvent;

import lombok.extern.slf4j.Slf4j;

/**
 * 
 * 
 * @Description: 本地环境变动修改 包含文件环境变动 和  spring 环境参数变动
 * @author xingyuan
 * @date 2023年3月20日 上午10:57:23
 */
@Component
@Slf4j
public class SpringEnvironmentChangeListener extends AbstractAsyncEventObserver implements ApplicationListener<EnvironmentChangeEvent> {

	
	
	@Override
	public void onApplicationEvent(EnvironmentChangeEvent event) {
		log.info("监听到环境配置刷新事件,重新刷新配置参数");
		SpringUtil.getBean(SpringEnvironmentProperties.class).restCaches();
		
		Properties.restCache();

		SpringRobot.getInstance().invokeRobotChange();
	}
	
	
	/**
	 * 文件系统刷新
	 * @param event
	 */
	@Subscribe
	public void event(SystemConfigModifiedEvent event) {
		log.info("监听到本地文件刷新事件,重新刷新配置参数");
		SpringUtil.getBean(SpringEnvironmentProperties.class).restCaches();
		
		Properties.restCache();
	}
	
}
